const network = require('../../utils/network.js')
const loginUtil = require('../../utils/login.js')

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  pageSize:8,
  page:1,
  last:false,
  data: {
    userInfo:null,
    list:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.accountList();
  },

// 账单记录
  accountList:function(){
    const { sn } = loginUtil.loadLoginInfo();
    const params = {
      "page": this.page,
      "pageSize": this.pageSize,
      "userSn": sn
    }
    network.requestLoading('mp/service/user/userIntegralList', params, '请求中', (res) => {

      const list_old = this.data.list ;
      const list_new = res.data.content ;
      this.setData({
        list: list_old.concat(list_new),
      });
      const pageable = res.data.pageable ;
      this.page = pageable.offset+2 ;
      this.last = res.data.last ;
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const loginInfo = loginUtil.loadLoginInfo();
    network.getRequest('mp/service/user/info', 'accesstoken=' + loginInfo.accessToken, (res) => {
      app.globalData.userInfo = res.data;
      this.setData({
        userInfo: res.data
      })
    }, err => {
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.last)return;
    this.accountList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },


  // 积分充值
  coinCharge: function () {
    wx.navigateTo({
      url: '/pages/charge/coin-charge',
    })
  },

  withdraw: function () {
    wx.navigateTo({
      url: '/pages/withdraw/withdraw',
    })
  }
})